package com.mica.erp.system.action;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import com.mica.erp.system.model.UserInfo;
import com.mica.erp.system.service.UserInfoService;
import com.mica.generic.GenericAction;
import com.mica.generic.GenericContant;

public class LoginAction extends GenericAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5463976058086776420L;

	@Override
	public String execute() throws Exception {
		UserInfo userInfo = userInfoService.validataUser(loginName, passWord);
		if(null==userInfo){
			return INPUT;
		}
		this.session().put(GenericContant.SESSION_KEY, userInfo);
		return SUCCESS;
	}
	
	public String logout()throws Exception{
		HttpSession hs = this.httpSession();
		hs.removeAttribute(GenericContant.SESSION_KEY);
		hs.invalidate();
		return SUCCESS;
	}
	
	@Autowired
	private UserInfoService userInfoService;
	private String loginName;

	private String passWord;

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}
}
